package cn.phonevane.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.phonevane.dao.UserDao;

public class UserDaoImpl extends HibernateDaoSupport implements UserDao{
	
	/**
	 * 用户登录
	 * @param username
	 * @param password
	 * @return 集合
	 */
	public List query(final String username,final String password,final String hql) {
		


		List rs = getHibernateTemplate().executeFind(new HibernateCallback() {

			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {

				Query query = session.createQuery(hql);
				query.setParameter("userName", username);
				query.setParameter("userPass", password);
				List rs = query.list();
				logger.info("query successful!");
				return rs;

			}
		});
		return rs;
	}
	
	/**
	 * 用户注册
	 * @param username
	 * @return list
	 */
	public List query(final String username,final String hql) {
		
		List rs = getHibernateTemplate().executeFind(new HibernateCallback() {

			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {

				Query query = session.createQuery(hql);
				query.setParameter("userName", username);
				List rs = query.list();
				logger.info("query successful!");
				return rs;
			}
		});
		return rs;
		
	}

}
